package testView;
import model.Puzzle;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * @author Beth Katz
 *
 * Tests the puzzle class. JUnit4 version.
 */
public class PuzzleTest {
	private char[ ][ ] m = { 
			{'p', 'o', 'o', 'w', 's'}, // row 1 in puzzle
			{'s', 'a', 'o', 'a', 'h'}, // row 2
			{'g', 'n', 'u', 'p', 'e'}, // row 3
			{'s', 'u', 'p', 'o', 'd'}  // row 4
	};

	private char[ ][ ] m2 = {
			{'h', 'e', 'l', 'l', 'o'}
	};

	private char[ ][ ] m3 = {
			{'h', 'e'},
            {'a', 'm'}
	};
	private Puzzle p;

	/*
	 * test finding words going in northeast direction
	 */
	@Test
	public void puzzleNE() {
		String theAnswer;
		
		p = new Puzzle(m);
		theAnswer = p.locationInPuzzle("now");
 		assertTrue(theAnswer.equalsIgnoreCase("now at 3,2 going NE\n"));
	}
	
	/*
	 * test finding words going in south direction
	 */
	@Test
	public void puzzleS() {
		String theAnswer;
		
		p = new Puzzle(m);
		theAnswer = p.locationInPuzzle("shed");
 		assertTrue(theAnswer.equalsIgnoreCase("shed at 1,5 going S\n"));
		theAnswer = p.locationInPuzzle("she");
 		assertTrue(theAnswer.equalsIgnoreCase("she at 1,5 going S\n"));
	}

	/*
	 * test finding words going in west direction
	 */
	@Test
	public void puzzleW() {
		String theAnswer;
		
		p = new Puzzle(m);
		theAnswer = p.locationInPuzzle("swoop");
		assertTrue(theAnswer.equalsIgnoreCase("swoop at 1,5 going W\n"));
	}

	/*
	 * test finding words going in north direction
	 */
	@Test
	public void puzzleN() {
		String theAnswer;

		p = new Puzzle(m);
		theAnswer = p.locationInPuzzle("paw");
		assertTrue(theAnswer.equalsIgnoreCase("paw at 3,4 going N\n"));
	}

	/*
	 * test finding words going in east direction
	 */
	@Test
	public void puzzleE() {
		String theAnswer;

		p = new Puzzle(m2);
		theAnswer = p.locationInPuzzle("hello");
		assertTrue(theAnswer.equalsIgnoreCase("hello at 1,1 going E\n"));
	}

        /*
	 * test finding words not in the puzzle
	 */	
	@Test
	public void puzzleWordNotFound() {
		String theAnswer;
		
		p = new Puzzle(m);
		theAnswer = p.locationInPuzzle("rain");
		assertTrue(theAnswer.length( ) == 0);
	}

    /*
	 * test reporting of puzzle size
	 */
	@Test
	public void rowsAndColumns() {
		int theAnswer;

		p = new Puzzle(m);
		theAnswer = p.numberOfColumns( );
		assertTrue(theAnswer == 5);
		theAnswer = p.numberOfRows( );
		assertTrue(theAnswer == 4);
		p = new Puzzle(m2);
		theAnswer = p.numberOfColumns( );
		assertTrue(theAnswer == 5);
		theAnswer = p.numberOfRows( );
		assertTrue(theAnswer == 1);
		p = new Puzzle(m3);
		theAnswer = p.numberOfColumns( );
		assertTrue(theAnswer == 2);
		theAnswer = p.numberOfRows( );
		assertTrue(theAnswer == 2);
	}

}
